﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SchedulerControl
{
    public partial class ScheduleItemControl : UserControl
    {
        private DateTime _currentViewDate = DateTime.Now;
        public DateTime CurrentViewDate
        {
            get { return _currentViewDate; }
            set
            {
                var monthNames = new PersianCalendar.PersianMonthNames();
                var dayNames = new PersianCalendar.PersianWeekDayNames();

                _currentViewDate = value;

            }
        }


        private string _text;
        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }


        



        private Rect _moveBoundry;
        public Rect MoveBoundry
        {
            get { return _moveBoundry; }
            set { _moveBoundry = value; }
        }

        
        public bool IsInEditMode { get; set; }

        public ScheduleItemControl()
        {
            InitializeComponent();
            IsInEditMode = false;
            tbScheduleDescriptionEdit.TextChanged += new TextChangedEventHandler(tbScheduleDescriptionEdit_TextChanged);
           
        }

        void tbScheduleDescriptionEdit_TextChanged(object sender, TextChangedEventArgs e)
        {
            //_metaData.Subject = tbScheduleDescriptionEdit.Text;
        }



        public static readonly DependencyProperty ScheduleDescriptionProperty = DependencyProperty.Register("ScheduleDescription"
            , typeof(string), typeof(ScheduleItemControl), new PropertyMetadata(NotifyScheduleDescriptionChanged));

        public string ScheduleDescription
        {
            get { return (string)GetValue(ScheduleDescriptionProperty); }
            set
            {
                SetValue(ScheduleDescriptionProperty, value);
                this.tbScheduleDescription.Text = value;
                this.tbScheduleDescriptionEdit.Text = value;
            }
        }

      

        private static void NotifyScheduleDescriptionChanged(DependencyObject dpObj, DependencyPropertyChangedEventArgs change)
        {
            string scheduleDescription = (string)change.NewValue;
            ((ScheduleItemControl)dpObj).ScheduleDescription = scheduleDescription;
        }

        private void UserControl_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	VisualStateManager.GoToState(this,"MouseEnter",true);

        }

        private void UserControl_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	//VisualStateManager.GoToState(this,"MouseLeave",true);
        }

        private void UserControl_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        	VisualStateManager.GoToState(this,"Click",true);
        }

        public void ShowToolbar()
        {
            VisualStateManager.GoToState(this, "MouseEnter", true);
        }

        private void grid_MouseEnter(object sender, MouseEventArgs e)
        {
            int iiii = 0;
        }


        public void SwitchToEdit()
        {
            this.tbScheduleDescriptionEdit.Text = this.tbScheduleDescription.Text; 
            this.tbScheduleDescriptionEdit.Visibility = System.Windows.Visibility.Visible;
            this.tbScheduleDescription.Visibility = System.Windows.Visibility.Collapsed;
            IsInEditMode = true;
        }


        public void SwitchToView()
        {
            this.tbScheduleDescriptionEdit.Visibility = System.Windows.Visibility.Collapsed;
            this.tbScheduleDescription.Visibility = System.Windows.Visibility.Visible;
            this.tbScheduleDescription.Text = this.tbScheduleDescriptionEdit.Text;
            IsInEditMode = false;
        }
    }
}
